package com.wskj.controller.common;

import com.wskj.common.core.controller.BaseController;
import com.wskj.common.core.domain.AjaxResult;
import com.wskj.common.core.domain.entity.SysUser;
import com.wskj.common.core.domain.model.LoginUser;
import com.wskj.system.service.ISysUserService;
import com.wskj.workbench.component.SysPermissionService;
import com.wskj.workbench.component.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;


@Api(tags = "生成token控制器")
@AllArgsConstructor
@RestController
@RequestMapping("/api/token")
public class ApiTokenController extends BaseController {

    private final ISysUserService sysUserService;

    private final TokenService tokenService;
    private final SysPermissionService sysPermissionService;

    /**
     * @description: 生成令牌方便测试的时候使用
     * @author: kubilewang
     **/
    @ApiOperation("生成令牌")
    @GetMapping("/createToken")
    public AjaxResult<String> createToken(@ApiParam("用户id") @RequestParam String userId) {

        SysUser sysUser = sysUserService.getById(userId);


        LoginUser loginUser = new LoginUser();
        loginUser.setUser(sysUser);
        loginUser.setPlatform(2);


        String token = tokenService.createToken(loginUser);

        return AjaxResult.success("生成令牌成功", "Bearer " + token);
    }

}
